package edu.hwadee.serviceImpl;

import java.util.List;

import edu.hwadee.entity.Companycooperation;
import edu.hwadee.service.CompanycooperationService;

public class CompanycooperationServiceImpl extends BasicServiceImpl implements CompanycooperationService {

	@Override
	public boolean save(Companycooperation companycooperation) {
		try {
			getCompanycooperationDAO().save(companycooperation);
			return true;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}

	@Override
	public boolean delete(Companycooperation companycooperation) {
		try {
			getCompanycooperationDAO().delete(companycooperation);
			return true;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Companycooperation> search(Companycooperation companycooperation) {
		try {
			return (List<Companycooperation>)getCompanycooperationDAO().findByExample(companycooperation);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	@Override
	public Companycooperation searchById(Integer companycooperationId) {
		try {
			return getCompanycooperationDAO().findById(companycooperationId);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	@Override
	public boolean update(Companycooperation companycooperation) {
		try {
			if(searchById(companycooperation.getCompanycooperationId()) != null) {
				getCompanycooperationDAO().merge(companycooperation);
				return true;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Companycooperation> showAll() {
		try {
			return (List<Companycooperation>)getCompanycooperationDAO().findAll();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
}
